//
//  LBPayFaileVC.m
//  V-Learn
//
//  Created by Apple on 2019/2/12.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBPayFaileVC.h"
#import "HomeViewController.h"
#import "CourseDetailsViewController.h"
@interface LBPayFaileVC ()

@end

@implementation LBPayFaileVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}

- (void)setupUI{
    self.navigationItem.title = @"确认订单";
    self.view.backgroundColor = rgb(242,242,242);
    UIImageView *bgImageView = [[UIImageView alloc] init];
    bgImageView.image = [UIImage imageNamed:@"wk_bg_pay"];
    [self.view addSubview:bgImageView];
    [bgImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(64*kScaleFit);
        make.height.mas_equalTo(150*kScaleFit);
    }];
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    [self.view addSubview:bgView];
    [bgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25*kScaleFit);
        make.right.mas_equalTo(-25*kScaleFit);
        make.top.mas_equalTo((70+64)*kScaleFit);
        make.height.mas_equalTo(400*kScaleFit);
    }];
    UIImageView *icon = [[UIImageView alloc] init];
    icon.image = [UIImage imageNamed:@"wk_pay_fail"];
    [bgView addSubview:icon];
    [icon makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40*kScaleFit);
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *successLab = [UILabel labelWithText:@"支付失败" andTextColor:rgb(51,51,51) andName:nil andFontSize:19];
    successLab.numberOfLines = 1;
    [bgView addSubview:successLab];
    [successLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(icon.mas_bottom).mas_equalTo(15);
        //        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *nameLab = [UILabel labelWithText:@"您未能成功购买<<课程名称>>，" andTextColor:rgb(51,51,51) andName:nil andFontSize:17];
    [bgView addSubview:nameLab];
    [nameLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(successLab.mas_bottom).mas_equalTo(30);
        //        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UILabel *nameLab2 = [UILabel labelWithText:@"请重新支付" andTextColor:rgb(51,51,51) andName:nil andFontSize:17];
    [bgView addSubview:nameLab2];
    [nameLab2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameLab.mas_bottom).mas_equalTo(0);
        //        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.mas_equalTo(bgView);
    }];
    
    UIButton *goStudyBtn = [[UIButton alloc] init];
    [goStudyBtn setTitle:@"去支付" forState:UIControlStateNormal];
    [goStudyBtn setBackgroundImage:LBImage(@"wk_pay_button") forState:UIControlStateNormal];
    goStudyBtn.titleLabel.font = [UIFont systemFontOfSize:19];
    [goStudyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [goStudyBtn addTarget:self action:@selector(clickGoPayBtn:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:goStudyBtn];
    [goStudyBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(nameLab2.mas_bottom).mas_equalTo(35);
        make.height.mas_equalTo(40);
    }];
    
    UIButton *goHomeBtn = [[UIButton alloc] init];
    [goHomeBtn setTitle:@"回首页" forState:UIControlStateNormal];
    [goHomeBtn setBackgroundImage:LBImage(@"wk_pay_button_blue") forState:UIControlStateNormal];
    goHomeBtn.titleLabel.font = [UIFont systemFontOfSize:19];
    [goHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [goHomeBtn addTarget:self action:@selector(clickHomeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:goHomeBtn];
    [goHomeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(goStudyBtn.mas_bottom).mas_equalTo(35);
        make.height.mas_equalTo(40);
    }];
    
}
#pragma mark - 去支付
- (void)clickGoPayBtn:(UIButton *)sender{
        [self.navigationController popViewControllerAnimated:YES];
//    for (UIViewController *controller in self.navigationController.viewControllers) {
//        if ([controller isKindOfClass:[CourseDetailsViewController class]]) {
//            CourseDetailsViewController *vc =(CourseDetailsViewController *)controller;
//            [self.navigationController popToViewController:vc animated:YES];
//        }
//    }
}
#pragma mark - 回首页
- (void)clickHomeBtn:(UIButton *)sender{
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[HomeViewController class]]) {
            HomeViewController *vc =(HomeViewController *)controller;
            [self.navigationController popToViewController:vc animated:YES];
        }
    }
    
    
}

@end
